package com.handtransaction.service.impl;

import com.handtransaction.dao.GoodsDao;
import com.handtransaction.entity.Goods;
import com.handtransaction.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YAO
 * @create 2021-03-31 18:29
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    GoodsDao goodsDao;


    @Override
    public void AddGoods(Goods goods) {
        goodsDao.addGoods(goods);
    }

    @Override
    public void AddGoods2(Goods goods) {
        goodsDao.addGoods2(goods);
    }

    @Override
    public void DeleteGoodsByGid(Integer gid) {
        goodsDao.deleteGoodsByGid(gid);
    }

    @Override
    public void updateGoods(Goods goods) {
        goodsDao.updateGoods(goods);
    }

    @Override
    public Goods QueryGoodBygid(Integer gid) {
        return goodsDao.queryGoodBygid(gid);
    }

    @Override
    public List<Goods> QueryGoodBygcid(String gcid) {
        List<Goods> goods = goodsDao.queryGoodsBygcid(gcid);
        if (goods.isEmpty()) {
            return null;
        } else {
            return goods;
        }
    }

    @Override
    public List<Goods> QueryGoodBygm(String gmessage) {
        String[] a = gmessage.split("\\s+");
        gmessage="";
        for(int i=0;i<a.length;i++){
            gmessage+="+"+a[i]+"* ";
        }
        List<Goods>goods=goodsDao.queryGoodsBygm1(gmessage);
        if(a.length==1
        ){
            if(goods.size()==0||a[0].length()==1)
                goods=goodsDao.queryGoodsBygm("%"+a[0]+"%");
            else
                return goods;
        }
        return goods;
    }


    @Override
    public List<Goods> QueryGoods() {
        List<Goods> list = new ArrayList<Goods>();
        list = goodsDao.queryGoods();
        return list;
    }

    @Override
    public List<Goods> queryGoodsByGuid(int guid) {
        return goodsDao.queryGoodsByGuid(guid);
    }


    @Override
    public void updategtinyint(Goods goods) {
        goodsDao.updategtinyint(goods);
    }

}
